<template>
  <div class="headerAdmin">
    <!-- 网站LOGO 名字 -->
    <div class="logoTitle">
      <img src="../assets/logo-small.png" alt="logo">
      <span>基于区块链的数字作品版权保护系统</span>
    </div>
    <!-- 搜索框 -->
    <div>
      <el-input placeholder="开始搜索吧" v-model="searchInput" class="input-with-select">
        <el-select v-model="select" slot="prepend" placeholder="请选择">
          <el-option label="搜作者" value="1"></el-option>
          <el-option label="搜作品" value="2"></el-option>
        </el-select>
        <el-button slot="append" icon="el-icon-search" @click="search"></el-button>
      </el-input>
    </div>
    <!-- 右上角导航栏 -->
    <el-menu router :default-active="activeIndex+id" class="el-menu-demo" mode="horizontal" @select="handleSelect">
      <!-- 审核处理 -->
      <el-menu-item :index="work+id">
        <el-button type="text">审核处理</el-button>
      </el-menu-item>
      <!-- 申诉处理 -->
      <el-menu-item :index="appeal+id">
        <el-button type="text">申诉处理</el-button>
      </el-menu-item>
      <!-- 退出登录 -->
      <el-menu-item @click="signOut">退出登录</el-menu-item>
    </el-menu>
  </div>
</template>

<script>

export default {
  data () {
    return {
      id: 'admin',
      form: {
        userName: '',
        userType: '管理员',
        userAvtar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png'
      },
      options: [{
        value: '选项1',
        label: '按作者'
      }, {
        value: '选项2',
        label: '按作品名'
      }
      ],
      searchInput: '',
      select: '1',
      work: '/checkwork/',
      appeal: '/checkappeal/',
      activeIndex: '/checkwork/',
      // activeIndex2: '1',
      uploadAreaVisible: false,
      textarea: ''
    }
  },
  methods: {
    // 搜索
    search () {
      if (this.searchInput !== '') {
        // this.$router.push('/admin/search/' + this.select + '/' + this.searchInput)
        const id = 'admin'
        this.$router.push('/admin/' + id + '/search/' + this.select + '/' + this.searchInput)
        window.location.reload()
      } else {
        alert('请输入搜索内容')
      }
    },
    // 监听右上角导航栏
    handleSelect (key, keyPath) {
      console.log(key, keyPath)
    },
    // 监听退出登录按钮
    signOut () {
      this.$confirm('您确定要退出吗?', '退出当前账号', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(() => {
        // 注销用户信息之后
        // 返回welcome登录页面
        this.$router.push('/welcome')
        // const info = { userkey: localStorage.getItem('userKey') }
        // self.$store.dispatch('LogOut', info).then(() => { self.$router.push({ path: '/Login' }) }).catch(() => {})
      }).catch(() => {
        // 取消退出登录
      })
    }
  }
}
</script>

<style lang="less" scoped>
.headerAdmin {
  border-bottom: 1px solid #eee;
  background-color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #333;
  font-size: 20px;
  .logoTitle {
    display: flex;
    align-items: center;
    span {
      margin-left: 15px;
    }
  }
  .input-with-select .el-input-group__prepend {
    .el-select {
      width: 100px;
    }
    background-color: #fff;
    margin-right: 15px;
  }
}

.bell {
  margin-top: 10px;
  margin-right: 40px;
}
</style>
